package mylib.dir;

/**
 * Created with IntelliJ IDEA.
 * User: 1
 * Date: 16.07.12
 * Time: 20:15
 * To change this template use File | Settings | File Templates.
 */
public class Pair<A extends Comparable<A>, B extends Comparable<B>> implements Comparable<Pair> {

    private A first;
    private B second;

    @Override
    public int compareTo(Pair o) {
        int c = first.compareTo((A) o.first);
        if (c != 0)
            return c;
        return second.compareTo((B) o.second);
    }

    public Pair(A first, B second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public String toString() {
        return "(" + first + "," + second + ")";
    }

    public A getFirst() {
        return first;
    }

    public void setFirst(A first) {
        this.first = first;
    }

    public B getSecond() {
        return second;
    }

    public void setSecond(B second) {
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pair pair = (Pair) o;

        if (!first.equals(pair.first)) return false;
        if (!second.equals(pair.second)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = first.hashCode();
        result = 31 * result + second.hashCode();
        return result;
    }
}
